package engine.newUi
{
	import engine.control.MiniLoadingBar;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.data.View;
	import engine.data.ViewObject;
	import engine.event.SoundEvent;
	import engine.logic.DoubleClickManager;
	import engine.logic.tips.TipsManage;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.window.NxWindowEvent;
	import newx.com.loader.SwfLoader;

	/**
	 * 
	 * @author gaoyq
	 * 
	 */
	public class SkillLogic
	{
		
		/**数据模型*/
		private 	var _model			:ModelLocator;
		/**主角所有技能***/
		private var _skilltopArr:Array = [];
		/**已经学得技能**/
		private var _showSkillArr:Array = [];
		/***当前需要显示的小技能***/
		private var _curSkillArr:Array = [];
		public static var _self:SkillLogic;
		
		private var _ui:SkillUI;
		
		/**技能index***/
		private var index:int = 0;
		/**默认技能绑定*/
		private var skillBindIndex:int = -1;
		/***技能经验绑定*/
		private var skillExpBindIndex:int = -1;
		/**默认选中技能**/
		private var defultSkill:int;
		
		private var _doubleClickManager	: 	DoubleClickManager;
		/**双击单击的时候用的**/
		private var _configid:String;
		/***双击选择默认技能 的时候是不是显示最后的虚拟技能图标**/
		private var _doubleShowLastSkill:Boolean = false;
		
		private var sprite:Sprite =  new Sprite();
		public function SkillLogic()
		{
			
		}
		
		public static function getInstance():SkillLogic
		{
			if(_self == null)
			{
				_self =new SkillLogic();
			}
			return _self;
		}
		
		public function Init():void
		{
			_model = ModelLocator.getInstance();
			//成功学习新技能
//			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_UPGRADE_SKILL_ID),studySkillOkHandle);
			_doubleClickManager	= DoubleClickManager.getInstance();
			
			_doubleClickManager.addDoubleClick( SkillLogic, singleClick, doubleClick );
		}
		
		private function singleClick(e:MouseEvent):void
		{
			setLastSkill();

			getCurSkills(_configid);
		}
		
		/**
		 *设置并返回当前的SkillView 
		 * @param index
		 * @return 
		 * 
		 */
		private function setSkillClip(index:int):NxClip
		{
			var mc:MovieClip = ui.skillView.getItemByIndex(index);
			var skillClip:NxClip; 
			
			if(mc["skillClip"] == null)
			{
				skillClip = new NxClip();
				mc.face.addChild(skillClip);
				mc["skillClip"] = skillClip;
			}else
			{
				skillClip = mc["skillClip"];
			}
			return skillClip;
		}
		
		
		private function setLastSkill():void
		{
			var len:int = _showSkillArr.length;
			var allLen:int = _skilltopArr.length;
			var configid:String = _skilltopArr[len];
			//			setViewSkill();
			if(len < allLen)
			{
//				var mc:MovieClip = ui.skill_mc.content["skilltop"+len];
				var mc:MovieClip = ui.skillView.getItemByIndex(len);
				var skillClip:NxClip = setSkillClip(len); 

				skillClip.mouseChildren = true;
				skillClip.source  = ResPath.JPG+"Icon_"+configid+".jpg";//ResManager.newResClass("skilltop_"+len) as MovieClip;
				skillClip.visible = true;
				skillClip.buttonMode = true;
				mc.addEventListener(MouseEvent.CLICK,onsSelectClickHandle);
				mc.addEventListener(MouseEvent.MOUSE_OVER,onjmdOverHandle);
				mc.addEventListener(MouseEvent.MOUSE_OUT,onjmdOutHandle);
				mc.data = StaticIni.getIniObj(configid);
				mc.data["ConfigID"] = configid;
				mc.data["isshow"] = getAllSkill(configid)?1:0;
				mc.visible = true;
//				skillClip.source.gotoAndStop(1);
				skillClip.alpha = .5;
				
			}
		}
		
		public function checkIsCanStudy():Boolean
		{
			var allSkillArr:Array = [];
			var Prof:int = _model.scene.Role.getPlayerProf();
			_skilltopArr = StaticIni.getIniVar("allskill_"+Prof,"skill").split(",");
			
			for(var i:int = 0;i<_skilltopArr.length;i++)
			{
				var liteSkillArr:Array = StaticIni.getIniVar("skilltree_"+_skilltopArr[i],"skill").split(",");
				for(var j:int = 0;j<liteSkillArr.length;j++)
				{
					allSkillArr.push(liteSkillArr[j]);
				}
				allSkillArr.push(_skilltopArr[i]);
			}
			var skillexp:int = _model.scene.Role.GetPropertiesEx("SkillExp");
			for(var m:int = 0;m<allSkillArr.length;m++)
			{
				if(!getAllSkill(allSkillArr[m]))
				{
					var needExp:int = int(StaticIni.getIniVar(allSkillArr[m],"NeedExp"));	
					if(skillexp >= needExp)
					{
						return true;
					}
				}
			}
			return false;
		}
		
		private function doubleClick(e:MouseEvent):void
		{
//			var mc:MovieClip = e.currentTarget as MovieClip;
//
//			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SET_DEFAULT_SKILL,int(mc.data["ConfigID"]));
//			
//			_doubleShowLastSkill = true;
		}
	
		private function studySkillOkHandle(e:CustomMsgEvent):void
		{
			ui.lab_skillCount.htmlStr = StaticIni.getSwfLangStrVar( "UIString_1000039",[_model.scene.Role.GetProperties("SkillExp")]);
			var index:int = _skilltopArr.indexOf(String(e.pList[0]));
//			var mc:NxClip = e.currentTarget as NxClip;
//			var index:int = _curSkillArr.indexOf(skillClip.data.GetProperties("configid"));
			if(index  != -1)
			{
				var img:MovieClip = ui.jm_mc.content["skill_"+index]["skilltop"] as MovieClip;
				
				var skillClip:NxClip =  img.getChildAt(0) as NxClip;
				var skillClip1:NxClip = setSkillClip(index); 
				var mc:MovieClip = ui.skillView.getItemByIndex(index);

				ui.skillEff.x = mc.x -30;
				ui.skillEff.y = mc.y -30;
				ui.skillEff.gotoAndPlay(1);
				ui.skillEff.visible = true;
				ui.skillEff.addFrameScript(ui.skillEff.totalFrames-1,mcstop);
				function mcstop():void
				{
					ui.skillEff.visible = false;
					ui.skillEff.stop();
					ui.skillEff.addFrameScript(ui.skillEff.totalFrames-1,null);
					getLocalSkillTree();
					getCurSkills();
					setViewSkill();
				}
				_model.dispatchEvent(new SoundEvent(SoundEvent.SKILL_NEW));
			}else
			{
				getLocalSkillTree();
				getCurSkills();
			}
		}

		private function  loadSkillUi():void
		{
			ui.showOrHide();
		}
		
		private function onSkilladdHandle(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			getLocalSkillTree();
			getCurSkills();
			setViewSkill();
		}

		private function onSkillremoveHandle(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			getLocalSkillTree();
			getCurSkills();
			setViewSkill();
		}
		/**
		 * 从视图中查找是不是存在 此SKILL
		 * @param skillid
		 * @return Boolean
		 * 
		 */
		public function getAllSkill(skillid:String):Boolean
		{
			var skillView:View = _model.scene.GetView(View.VIEWPORT_SKILL);
			var isadd:Boolean =  false;
			skillView.getDataForEach(
				function(proName:String,proValue:*):void
				{
					if(proValue is ViewObject)
					{
						if(proValue.GetProperties("ConfigID") == skillid)
						{
							isadd = true;
						}
					}
				}
			);
			return isadd;
		}
		
		public function showUI():void
		{
			MiniLoadingBar.getInstance().show("加载中....");
//			SwfLoader.StartLoad(StageInfo.swfResPath + "skillBg.swf",null,compeleFunc,[onLoading]);
			SwfLoader.StartLoad(StageInfo.swfResPath + "skillui.swf",null,compeleFuncshow,[onLoading]);
		}
		
		private function compeleFuncshow(val:DisplayObject, pList:Array = null):void
		{
			ui.skill_mc.source = val;
			getLocalSkillTree();
			getCurSkills();
			setViewSkill();
			loadSkillUi();
		}
		
		private function compeleFunc(val:DisplayObject, pList:Array = null):void
		{
			ui.bg.source = val;
			
			MiniLoadingBar.getInstance().show("加载中....");
			SwfLoader.StartLoad(StageInfo.swfResPath + "skillui.swf",null,compeleFuncshow,[onLoading]);
		}
		
		private function onLoading(e:Event):void
		{
			
			var pe:ProgressEvent=e as ProgressEvent;
			if(pe)
				MiniLoadingBar.getInstance().progress=pe.bytesLoaded/pe.bytesTotal;
		}
		
		public function getStudyedSkill():Array
		{
			var skillView:View = _model.scene.GetView(View.VIEWPORT_SKILL);
			var skillArr:Array = [];
			skillView.getDataForEach(
				function(proName:String,proValue:*):void
				{
					if(proValue is ViewObject)
					{
						if(proValue.GetProperties("IsCommonSkill") == 0)
						{
							skillArr.push(proValue.GetProperties("ConfigID"));
						}
					}
				}
			);
			return skillArr;
		}
		
		/**
		 *获取本地配置的技能树 
		 * 
		 */
		private function getLocalSkillTree():void
		{
			var Prof:int = _model.scene.Role.getPlayerProf();
			_skilltopArr = StaticIni.getIniVar("allskill_"+Prof,"skill").split(",");
			_showSkillArr = [];
			for(var i:int = 0;i<_skilltopArr.length;i++)
			{
				if(getAllSkill(_skilltopArr[i]))
				{
					_showSkillArr.push(_skilltopArr[i]);
				}else
				{
					return;
				}
			}
			
		}
		

		
		/**
		 * 获取当前需要显示的小技能
		 * 
		 */
		private function getCurSkills(configid:String = null):void
		{
			if(configid!=null)
			{
				for(var i:int = 0;i<_skilltopArr.length;i++)
				{
					if(configid == _skilltopArr[i])
					{
						index = i;
						break;
					}
				}
			}else
			if(_showSkillArr.length < _skilltopArr.length)
			{
				index = _showSkillArr.length;	
			}else
			{
				index = _showSkillArr.length -1;
			}
			
			SwfLoader.StartLoad("res/swf/skill_"+index+".swf",null,onComplete);
//			var mc:MovieClip =	ResManager.getResContentCopy("skill_"+index) as MovieClip;
//			ui.jm_mc.source = mc;
			_curSkillArr =  StaticIni.getIniVar("skilltree_"+_skilltopArr[index],"skill").split(",");
			_curSkillArr.push(_skilltopArr[index]);
//			setViewSkill();
//			setAllSkill();
		}
	
		private function onComplete(val:DisplayObject, pList:Array):void
		{
			var mc:MovieClip;
			mc = val as MovieClip;
			ui.jm_mc.source = Object(mc);
			
//			setAllSkill();
		
		}
			
		
		public function set skillSelect(value:int):void 
		{
			defultSkill = value;
			setViewSkill();
		}
		
		public function set skillExpHandle(value:int):void
		{
			ui.lab_skillCount.htmlStr = StaticIni.getSwfLangStrVar( "UIString_1000039",[_model.scene.Role.GetProperties("SkillExp")]);
		}
		
		/**
		 *设置已经学习成功的技能 
		 * 
		 */
		private function setViewSkill():void
		{
//			_showSkillArr.push("17000104");
			var len:int = _showSkillArr.length;
			for(var i:int = 0;i< 10 ;i++)
			{
				var configid:String = _showSkillArr[i];
				
//				var mc:MovieClip = ui.skill_mc.content["skilltop"+i];
//				var skillClip:NxClip; 
				var moc:MovieClip = ui.skillView.getItemByIndex(i) as MovieClip;
				var skillClip:NxClip = setSkillClip(i); 
//					
//				if(moc["skillClip"] == null)
//				{
//					skillClip = new NxClip();
//					moc.addChild(skillClip);
//					moc["skillClip"] = skillClip;
//				}else
//				{
//					skillClip = moc["skillClip"];
//				}
//				if(mc.numChildren <=0)
//				{
//					skillClip = new NxClip();
//					mc.addChild(skillClip);
//				}
//				skillClip =  mc.getChildAt(0) as NxClip;
//				if(!skillClip)
//				{
//					skillClip = new NxClip();
//					mc.addChild(skillClip);
//				}
				if(i < len)
				{
					
					skillClip.source  = ResPath.JPG+"Icon_"+configid+".jpg";//ResManager.newResClass("skilltop_"+i) as MovieClip;
					skillClip.visible = true;
					skillClip.buttonMode = true;
					moc.parent.mouseChildren=true;
					moc.addEventListener(MouseEvent.CLICK,onSkillClickHandle);
					moc.addEventListener(MouseEvent.MOUSE_OVER,onjmdOverHandle);
					moc.addEventListener(MouseEvent.MOUSE_OUT,onjmdOutHandle);
					moc.data = StaticIni.getIniObj(configid);
					moc.data["ConfigID"] = configid;
					moc.data["isshow"] = getAllSkill(configid)?1:0;
//					if(configid == String(defultSkill))
//					{
//						MovieClip(skillClip.source).gotoAndStop(3);
//					}else
//					{
//						MovieClip(skillClip.source).gotoAndStop(1);
//					}
					skillClip.alpha = 1;
//					mc.data = StaticIni.getIniObj(_showSkillArr[i]);
					moc.visible = true;
				}else
				{
					if(moc)
					{
						moc.visible = false;
						skillClip.source  = null
						skillClip.visible = false;
						skillClip.data.Properties = null;
					}
				}
			}
			if(_doubleShowLastSkill == true && index!=len)
			{
				setLastSkill();
			}
			setbtnView();
		}
		
		/**
		 *虚拟的技能图标 
		 * @param e
		 * 
		 */
		private function onsSelectClickHandle(e:MouseEvent):void
		{
			var mc:MovieClip = e.currentTarget as MovieClip;
			mc.visible = false;
			mc.removeEventListener(MouseEvent.CLICK,onsSelectClickHandle);
			mc.removeEventListener(MouseEvent.MOUSE_OVER,onjmdOverHandle);
			mc.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
			mc.removeEventListener(MouseEvent.MOUSE_OUT,onjmdOutHandle);
//			var skillClip:NxClip = mc.getChildAt(0) as NxClip;
			var skillClip:NxClip = mc["skillClip"];
			skillClip.source  = null
			skillClip.visible = false;
			skillClip.data.Properties = null;
			getCurSkills(e.currentTarget.data["ConfigID"]);
			TipsManage.hideTips();
			setbtnView();
		}
		
		private function onSkillClickHandle(e:MouseEvent):void
		{
			_configid = e.currentTarget.data["ConfigID"]
			_doubleClickManager.onClick( SkillLogic, e );
			setbtnView();
		}
		
		/**
		 *设置当前显示的小技能 
		 * 
		 */
		private function setAllSkill():void
		{
			var isCanUp:Boolean = false;//是不是可升级 的技能
			for(var i:int = 0;i<_curSkillArr.length;i++)
			{
				var configId:String = _curSkillArr[i];
				var img:MovieClip;
				var skillClip:NxClip;
				
				if(i == _curSkillArr.length-1)
				{
					img = ui.jm_mc.content["skill_"+index]["skilltop"] as MovieClip;
					if(img.numChildren <=0)
					{
						skillClip = new NxClip();
						img.addChild(skillClip);
					}
					skillClip =  img.getChildAt(0) as NxClip;
					if(!skillClip)
					{
						skillClip = new NxClip();
						img.addChild(skillClip);
					}
					skillClip.source = ResManager.newResClass("skilltop_"+index) as MovieClip;
				}else
				{
					img = ui.jm_mc.content["skill_"+index]["jmd_"+i] as MovieClip;
					var proe:Array = StaticIni.getIniVar("addProp_" + configId ,"r").split(",");
					var des:String = StaticIni.getSwfLangStrVar("Item_"+proe[0],[proe[1]]);
//					(ui.jm_mc.content["skill_"+index]["txt"+i]  as TextField).htmlText = des;
					if(img.numChildren <=0)
					{
						skillClip = new NxClip();
						img.addChild(skillClip);
					}
					skillClip =  img.getChildAt(0) as NxClip;
					if(!skillClip)
					{
						skillClip = new NxClip();
						img.addChild(skillClip);
					}
					skillClip.source = ResManager.newResClass("jmd") as MovieClip;
					skillClip.x = -1;
					skillClip.y = -1;
				}
				img.source = StageInfo.iconResPath  +  StaticIni.getIniVar(String(configId),"Icon") + ".jpg";

				img.visible = true;
				img.buttonMode = true;
				img.parent.parent.mouseChildren = true;
				img.addEventListener(MouseEvent.CLICK,onjmdClickHandle);
				img.addEventListener(MouseEvent.MOUSE_OVER,onjmdOverHandle);
				img.addEventListener(MouseEvent.MOUSE_OUT,onjmdOutHandle);
				img.data = StaticIni.getIniObj(configId);
				img.data["ConfigID"] = configId;
				img.data["isshow"] = getAllSkill(configId)?1:0;
				if(!isCanUp)
				{
					if(!getAllSkill(configId))
					{
						isCanUp = true;
						img.data["isshow"] = 2;
						var skillexp:int = _model.scene.Role.GetProperties("SkillExp");
						var needExp:int  = img.data["NeedExp"];
						if(skillexp < needExp)
						{
							MovieClip(skillClip.source).gotoAndStop(3); 
						}else
						{
							MovieClip(skillClip.source).gotoAndStop(2); 
						}
						
					}else
					{
						MovieClip(skillClip.source).gotoAndStop(1); 
					}
				}else
				{
					if(getAllSkill(configId))
					{
						MovieClip(skillClip.source).gotoAndStop(1); 
					}else
					{
						MovieClip(skillClip.source).gotoAndStop(3); 
//						skillClip.filters = [FilterUtil.GrayColorFilter];
					}
				}
				skillClip.alpha = 1;
			}
		}
		
		private function onjmdOverHandle(e:MouseEvent):void
		{
			var skillimg:MovieClip = e.currentTarget as MovieClip;
			skillimg.gotoAndStop(2);
			TipsMainLogic.instance.showByItem(TipsMainLogic.instance.getSkillItem(skillimg.data));
		}
		
		private function onjmdOutHandle(e:MouseEvent):void
		{
			e.currentTarget.gotoAndStop(1);
			TipsMainLogic.instance.hide();
		}
		private function onjmdClickHandle(e:MouseEvent):void
		{
			var mc:MovieClip = e.currentTarget as MovieClip;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SKILL_UPGRADE,int(mc.data["ConfigID"]));
//			_model.dispatchEvent(new CustomMsgEvent(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_UPGRADE_SKILL_ID),[ mc.data.GetProperties("configid")] ));
		}
		
		
		private function onOutClickHandle(e:MouseEvent):void
		{
			ui.hide();	
		}
		
		private function loadUI():void
		{
			MiniLoadingBar.getInstance().show("加载中....");
			//			SwfLoader.StartLoad(StageInfo.swfResPath + "skillBg.swf",null,compeleFunc,[onLoading]);
			SwfLoader.StartLoad(StageInfo.swfResPath + "skillui.swf",null,compeleloadFuncshow,[onLoading]);
		}
	
		private function compeleloadFuncshow(val:DisplayObject, pList:Array = null):void
		{
			ui.skill_mc.source = val;
			getLocalSkillTree();
			getCurSkills();
			setViewSkill();
		}
		
		public function BeforeShow():void
		{
			loadUI();
			setbtnView();
			ui.btn_out.visible = false;
			skillExpBindIndex = BindManage.getInstance().BindProp(_model.scene.Role,"SkillExp",this,"skillExpHandle");
			_doubleShowLastSkill = false;
//			skillBindIndex = BindManage.getInstance().BindProp(_model.scene.Role,"DefaultUltraSkill",this,"skillSelect");
//			sprite.graphics.beginFill(0x000000,1);
//			sprite.graphics.drawRect(-Capabilities.screenResolutionX/2,-Capabilities.screenResolutionY/2,
//				Capabilities.screenResolutionX*2,Capabilities.screenResolutionY*2);
//			sprite.graphics.endFill();
//			StageInfo.systemSpace.addChild(sprite);
//			ui.addChildAt(sprite,0);
			ui.lab_skillCount.htmlStr = StaticIni.getSwfLangStrVar( "UIString_1000039",[_model.scene.Role.GetProperties("SkillExp")]);

			addListenter();
		}
		
		public function AfterHide():void
		{
			removeListenter();
//			sprite.graphics.clear();
//			ui.removeChild(sprite);
			_doubleShowLastSkill = false;
		}
		
		private function onClickCloseHandle(e:NxWindowEvent):void
		{
			ui.hide();
			StageInfo.uiSpace.graphics.clear();
			BottomIndexUI.getInstance().visible = true;
		}
		
		
		private function onHelpOverClickHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStr("UIString_1000166"));	
		}
		
		private function onTipPicOverClickHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStr("UIString_1000165"));	
		}
		
		private function onHelpOutClickHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		
		private function leftClickHandle(e:MouseEvent):void
		{
			if(index > 0)
			{
				index --; 
				getCurSkills(_curSkillArr[index]);
			}
			setbtnView();
		}
		
		private function setbtnView():void
		{
//			ui.skillView.getItemByIndex(_showSkillArr.length).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			if(index < 1)
			{
				ui.btn_left.enabled = false;
			}else
			{
				ui.btn_left.enabled = true;
			}
			if(index >= _showSkillArr.length)
			{
				ui.btn_right.enabled = false;
				ui.skillView.getItemByIndex(_showSkillArr.length).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			}else
			{
				ui.btn_right.enabled = true;
				setLastSkill();
			}
		}
		private function rightClickHandle(e:MouseEvent):void
		{
			if(index < _showSkillArr.length)
			{
				index ++; 
				getCurSkills(_curSkillArr[index]);
			}
			setbtnView();
		}
		
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			ui.btn_out.addEventListener(MouseEvent.CLICK,onOutClickHandle);
			ui.btn_close.addEventListener(MouseEvent.CLICK,onOutClickHandle);
			
			ui.windowBG.nxWindowhelpBtn	.addEventListener(MouseEvent.MOUSE_OVER,onHelpOverClickHandle);
			ui.windowBG.nxWindowhelpBtn.addEventListener(MouseEvent.MOUSE_OUT,onHelpOutClickHandle);
			
			ui.skill_tipPic.addEventListener(MouseEvent.MOUSE_OVER,onTipPicOverClickHandle);
			ui.skill_tipPic.addEventListener(MouseEvent.MOUSE_OUT,onHelpOutClickHandle);
			
			ui.btn_left.addEventListener(MouseEvent.CLICK,leftClickHandle);
			ui.btn_right.addEventListener(MouseEvent.CLICK,rightClickHandle);
			
			
		}
		
		/**
		 *移除监听 
		 * 
		 */
		private  function removeListenter():void
		{
//			BindManage.getInstance().UnbindProp(_model.scene.Role,"DefaultUltraSkill",skillBindIndex);
			BindManage.getInstance().UnbindProp(_model.scene.Role,"SkillExp",skillExpBindIndex);
			ui.btn_out.removeEventListener(MouseEvent.CLICK,onOutClickHandle);
			ui.btn_close.removeEventListener(MouseEvent.CLICK,onOutClickHandle);
			
			ui.windowBG.nxWindowhelpBtn.removeEventListener(MouseEvent.MOUSE_OVER,onHelpOverClickHandle);
			ui.windowBG.nxWindowhelpBtn.removeEventListener(MouseEvent.MOUSE_OUT,onHelpOutClickHandle);
			
			ui.skill_tipPic.removeEventListener(MouseEvent.MOUSE_OVER,onTipPicOverClickHandle);
			ui.skill_tipPic.removeEventListener(MouseEvent.MOUSE_OUT,onHelpOutClickHandle);
			
			ui.btn_left.removeEventListener(MouseEvent.CLICK,leftClickHandle);
			ui.btn_right.removeEventListener(MouseEvent.CLICK,rightClickHandle);
		}
		
		public function get ui():SkillUI
		{
			if(_ui==null)
			{
				_ui	=	new SkillUI();
			}
			return _ui
		}
	}
}